<?php
/**
 * Created by PhpStorm.
 * User: TS
 * Date: 2017/4/4
 * Time: 20:55
 */
namespace apps\index\controller;

use apps\index\model\User;
use core\Cache;
use core\Controller;
use core\Service;
use core\DB;
use core\http\Request;
use core\Cookie;
use core\File;
use core\Session;

class index extends Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function c()
    {
        return (Request::getInstance());
    }

    public function upload()
    {
        if ($files = request()->get('files.image')) {
            $file = (new File($files['tmp_name']))->setUploadInfo($files);
            $info = $file->move('images');
            if($info){
                // 成功上传后 获取上传信息
                // 输出 jpg
                echo $info->getExtension();
                // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
                echo $info->getSaveName();
                // 输出 42a79759f284b767dfcb2a0197904287.jpg
                echo $info->getFilename();
            }else{
                // 上传失败获取错误信息
                echo $file->getError();
            }
        }

        return $this->fetch('files');
    }

    public function test()
    {
        return 'test-xxxxxxx12312312312321';
    }

    public function index()
    {
        return $this->fetch('index', ['cc' => createGuid()]);
    }

    public function testDb()
    {
        //return User::where('id', '<', '10')->get();
        DB::connect();
        return DB::table('user', 'default')->where('id', '<', 10)->get();
    }

    public function p()
    {
        return Service::getInstance('https://www.baidu.com/')->setMethod('get')->send('');
    }

    public function cache()
    {
        Cache::getInstance(
            [
                'scheme' => 'tcp',
                'host'   => '127.0.0.1',
                'port'   => 6379,
            ]
        )->set('cc','ddd');
        return Cache::getInstance()->get('cc');
    }

}


